﻿using SQLinq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleDatabaseAdapter
{
    public interface IAllData
    {
        /// <summary>
        /// Create table and columns if not exists
        /// </summary>
        void CheckTable();

        /// <summary>
        /// Execute query in AllData table
        /// </summary>
        /// <param name="query">SQL query</param>
        void ExucuteQuery(string query);

        /// <summary>
        /// Get data from AllData
        /// </summary>
        /// <param name="query">SQL query</param>
        /// <returns>Data</returns>
        DataTable GetData(string query);

        /// <summary>
        /// Get list items from AllData
        /// </summary>
        /// <param name="listName">List name</param>
        /// <param name="queryWhere">SQL query where</param>
        /// <param name="queryOrder">SQL query order</param>
        /// <returns>Data</returns>
        DataTable GetListItems(string listName, string queryWhere = "", string queryOrder = "");

        /// <summary>
        /// Get list items from AllData
        /// </summary>
        /// <param name="listId">List id</param>
        /// <param name="queryWhere">SQL query where</param>
        /// <param name="queryOrder">SQL query order</param>
        /// <returns>Data</returns>
        DataTable GetListItems(int listId, string queryWhere = "", string queryOrder = "");

        /// <summary>
        /// Get list items from AllData
        /// </summary>
        /// <param name="listData">List data</param>
        /// <param name="queryWhere">SQL query where</param>
        /// <param name="queryOrder">SQL query order</param>
        /// <returns>Data</returns>
        DataTable GetListItems(ListData listData, string queryWhere = "", string queryOrder = "");

        /// <summary>
        /// Get AllData items by Linq
        /// </summary>
        /// <typeparam name="T">AllData item type, based on AllDataItemBase</typeparam>
        /// <param name="query">Linq query</param>
        /// <returns>AllData items collection</returns>
        AllDataItemsCollection<T> GetItems<T>(SQLinq<T> query);

        /// <summary>
        /// Return empty list item
        /// </summary>
        /// <typeparam name="T">AllData item type, based on AllDataItemBase</typeparam>
        /// <param name="id">List id</param>
        /// <returns>Empty list item</returns>
        T GetNewListItem<T>(int id);

        /// <summary>
        /// Add new item in AllData
        /// </summary>
        /// <param name="newItem">New item</param>
        /// <returns>New item id</returns>
        long AddItem<T>(T newItem);

        /// <summary>
        /// Add new items in AllData
        /// </summary>
        /// <param name="newItems">New items</param>
        /// <returns>New items ids</returns>
        List<long> AddItems<T>(List<T> newItems);

        /// <summary>
        /// Update item in AllData
        /// </summary>
        /// <param name="newItem">Item to update</param>
        void UpdateItem(AllDataItemBase newItem);

        /// <summary>
        /// Update items in AllData
        /// </summary>
        /// <param name="newItems">Items to update</param>
        void UpdateItems(List<AllDataItemBase> newItems);

        /// <summary>
        /// Delete item from AllData
        /// </summary>
        /// <param name="id">Item id to delete</param>
        void DeleteItem(long id);

        /// <summary>
        /// Delete items from AllData
        /// </summary>
        /// <param name="ids">Items ids to delete</param>
        void DeleteItems(List<long> ids);
    }
}
